package com.incar.chuxing.utils;

import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Michael Pi on 2016/10/14.
 */
public class CheckRegexUtils {
    public static boolean checkPhoneNum(String str) {
       /* String regexp = "^1[2|3|4|5|6|7|8|9|0]\\d{9}$";
        Pattern pattern = Pattern.compile(regexp);
        Matcher matcher = pattern.matcher(str);*/
        return str.length() == 11;
    }

    public static boolean checkPassword(String str) {
        String regexp = "^[a-zA-Z0-9]{6,16}$";
        Pattern pattern = Pattern.compile(regexp);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }

    public static boolean checkIdCard(String str) {
        String regexp = "(^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}$)\n";
        Pattern pattern = Pattern.compile(regexp);
        Matcher matcher = pattern.matcher(str);
        return (matcher.matches());
    }

    public static boolean checkQRCode(String str) {
        String regexp = "([0-9]+)";
        Pattern pattern = Pattern.compile(regexp);
        Matcher matcher = pattern.matcher(str);
        return (matcher.matches());
    }

    public static boolean checkNickName(String str) {
        String regexp = "^[a-zA-Z\\u4E00-\\u9FA5\\\\d]*$";
        Pattern pattern = Pattern.compile(regexp);
        Matcher matcher = pattern.matcher(str);
        return (matcher.matches());
    }

    public static boolean checkParkName(String str) {
        str = str.trim();
        if (!TextUtils.isEmpty(str) && str.length() > 1) {
            int count = 0;
            Pattern pattern = Pattern.compile("\\p{P}");
            char c[] = str.toCharArray();
            for (int i = 0; i < c.length; i++) {
                Matcher matcher = pattern.matcher(String.valueOf(c[i]));
                if (matcher.matches()) {
                    count++;
                }
            }
            if (count < c.length) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}